/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.util;

import java.lang.reflect.Modifier;

public class ClassMarker extends BaseMarker {
	private final Class<?> markerClass;

	public ClassMarker(Class<?> markerClass) {
		super(markerClass.getName().toLowerCase());

		this.markerClass = markerClass;
	}

	public boolean hasMarkerClass(Class<?> markerClass) {
		return this.markerClass.equals(markerClass);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// TestFilter methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public boolean matches(Class<?> aClass) {
		return markerClass.isAssignableFrom(aClass) &&
			!Modifier.isAbstract(aClass.getModifiers());
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		
		if (object == null) {
			return false;
		}
		
		if (!getClass().equals(object.getClass())) {
			return false;
		}
		
		ClassMarker other = (ClassMarker) object;
		
		return other.hasMarkerClass(markerClass);
	}
	
	@Override
	public int hashCode() {
		return markerClass.hashCode();
	}
	
	@Override
	public String toString() {
		return "ClassMarker: " + markerClass;
	}
}